<template>
  <div class="container2">
    <!-- 操作记录dialog-->
    <el-dialog
      :title="title"
      width="1200px"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="viewVisible"
      class="tableDialog adjustDialogHeight"
    >
      <el-table
        size="mini"
        v-loading="loading"
        :data="tableData"
        style="width: 100%;"
        border
        :header-cell-style="{
          'background-color': '#eeeeee !important',
        }"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="index" label="序号" width="60">
          <template slot-scope="scope">
          <span>{{
            (page.pageNo - 1) * page.pageSize + scope.$index + 1
          }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="updateDate" label="修改时间" min-width="160">
        </el-table-column>
        <el-table-column prop="createBy.loginName" label="修改人" min-width="120"> </el-table-column>
        <el-table-column prop="operateOld" label="修改前" min-width="190">
          <template slot-scope="scope">
            <div v-if="!(scope.row.operateOld === undefined)">
              <p v-if="scope.row.operateOld.transCode !== undefined">派车单号：{{scope.row.operateOld.transCode}}</p>
              <p v-if="scope.row.operateOld.planCode !== undefined">发运计划：{{scope.row.operateOld.planCode}}</p>
              <p v-if="scope.row.operateOld.truckNumber !== undefined">车牌号：{{scope.row.operateOld.truckNumber}}</p>
              <p v-if="scope.row.operateOld.driverName !== undefined">司机姓名：{{scope.row.operateOld.driverName}}</p>
              <p v-if="scope.row.operateOld.deductWeight !== undefined">暗扣：{{scope.row.operateOld.deductWeight}}</p>
              <p v-if="scope.row.operateOld.deductWeightWater !== undefined">扣水：{{scope.row.operateOld.deductWeightWater}}</p>
              <p v-if="scope.row.operateOld.deductWeightImpurity !== undefined">扣杂：{{scope.row.operateOld.deductWeightImpurity}}</p>
              <p v-if="scope.row.operateOld.overloadAdjustWeight !== undefined">超载调整：{{scope.row.operateOld.overloadAdjustWeight}}</p>
              <p v-if="scope.row.operateOld.originalWeight !== undefined">原发数：{{scope.row.operateOld.originalWeight}}</p>
              <p v-if="scope.row.operateOld.allowLossWeight !== undefined">合理路耗：{{scope.row.operateOld.allowLossWeight}}</p>
            </div>
            <div v-else>--</div>
          </template>
        </el-table-column>
        <el-table-column prop="operateNew" label="修改后" min-width="190">
          <template slot-scope="scope">
            <div v-if="!(scope.row.operateNew === undefined)">
              <p v-if="scope.row.operateNew.transCode !== undefined">派车单号：{{scope.row.operateNew.transCode}}</p>
              <p v-if="scope.row.operateNew.planCode !== undefined">发运计划：{{scope.row.operateNew.planCode}}</p>
              <p v-if="scope.row.operateNew.truckNumber !== undefined">车牌号：{{scope.row.operateNew.truckNumber}}</p>
              <p v-if="scope.row.operateNew.driverName !== undefined">司机姓名：{{scope.row.operateNew.driverName}}</p>
              <p v-if="scope.row.operateNew.deductWeight !== undefined">暗扣：{{scope.row.operateNew.deductWeight}}</p>
              <p v-if="scope.row.operateNew.deductWeightWater !== undefined">扣水：{{scope.row.operateNew.deductWeightWater}}</p>
              <p v-if="scope.row.operateNew.deductWeightImpurity !== undefined">扣杂：{{scope.row.operateNew.deductWeightImpurity}}</p>
              <p v-if="scope.row.operateNew.overloadAdjustWeight !== undefined">超载调整：{{scope.row.operateNew.overloadAdjustWeight}}</p>
              <p v-if="scope.row.operateNew.originalWeight">原发数：{{scope.row.operateNew.originalWeight}}</p>
              <p v-if="scope.row.operateNew.allowLossWeight!==undefined">合理路耗：{{scope.row.operateNew.allowLossWeight}}</p>
            </div>
            <div v-else>--</div>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="operateState" min-width="160">
<!--          <template slot-scope="scope">-->
<!--            {{$dictUtils.getDictLabel("weightOperateState", scope.row.operateState, "")}}-->
<!--          </template>-->
          <template slot-scope="scope">
                  <div v-if="JSON.stringify(scope.row.flowState) === '{}'">
<!--                    <div class="state process" v-if="scope.row.operateState === -1" type="warning"><span></span>{{-->
<!--                      $dictUtils.getDictLabel("weightOperateState", scope.row.operateState, "")-->
<!--                    }}</div>-->
                    <div class="state empty" v-if="scope.row.operateState === 1 || scope.row.operateState === 101" type="info"><span></span>{{
                      $dictUtils.getDictLabel("weightOperateState", scope.row.operateState, "")
                    }}</div>
                    <div class="state process" v-if="scope.row.operateState === 2"><span></span>{{
                      $dictUtils.getDictLabel("weightOperateState", scope.row.operateState, "")
                    }}</div>
<!--                    <div class="state invalid"-->
<!--                      v-if="scope.row.operateState === 3 || scope.row.operateState === 4 "-->
<!--                      type="danger"-->
<!--                    >{{ $dictUtils.getDictLabel("weightOperateState", scope.row.operateState, "") }}</div-->
<!--                    >-->
                    <div class="state normal" v-if="scope.row.operateState === 100" type="success"><span></span>{{
                      $dictUtils.getDictLabel("weightOperateState", scope.row.operateState, "")
                    }}</div>
                  </div>
            <div v-else>
                    <div class="state process"
                      v-if="
                        scope.row.flowState.code === 0 ||
                        scope.row.flowState.code === 3 ||
                        scope.row.flowState.code === 4 ||
                        scope.row.flowState.code === 5
                      "
                      type="danger"
                    >{{ scope.row.flowState.status }}</div
                    >
                    <span v-if="scope.row.flowState.deleteReason"></span>
                    <div class="state process" v-if="scope.row.flowState.code === 2" type="primary"
                    ><span></span>{{ scope.row.flowState.status }} [{{
                        scope.row.flowState.currentTask.name
                      }}]</div
                    >
                    <div class="state process" v-if="scope.row.flowState.code === 100" type="success"><span></span>{{
                      scope.row.flowState.status
                    }}</div>
                  </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-link :underline="false" type="primary" @click="viewDetail(scope.row.procInsId)">详情</el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="page.pageSize"
        :current-page="page.pageNo"
        layout="total,prev, pager, next"
        :total="page.total"
      >
      </el-pagination>
      <span slot="footer" class="dialog-footer"></span>
    </el-dialog>
    <TaskForm flowTitle="详情" v-if="" :procInsId="procInsId" ref="TaskForm"></TaskForm>
  </div>
</template>
<script>
import {
  getList
} from '@/api/weightingManagent/operateDetail.js'
import TaskForm from '@/components/flow/TaskForm'
export default {
  components: {
    TaskForm
  },
  data () {
    return {
      page: { total: 0, pageSize: 10, pageNo: 1 },
      method: '',
      title: '',
      loading: false,
      tableData: [],
      recordForm: {
        weightId: ''
      },
      procInsId: '',
      editVisible: false,
      viewVisible: false
    }
  },
  methods: {
    init (method, row) {
      if (method === 'send') {
        this.viewVisible = true
        this.getList(this.page, '', '', row)
        this.title = '修改记录'
      }
    },
    viewDetail (row) {
      this.$refs.TaskForm.detailsVisible = true
      this.procInsId = row
    },
    getList (params, orderName, orderByAORC, trailId) {
      this.loading = true
      getList({
        pageSize: params.pageSize,
        pageNo: params.pageNo,
        orderBy: orderName,
        orderByAORC: orderByAORC,
        truckTrailId: trailId,
        operateType: 3
      }).then(({data}) => {
        if (data.code === '200') {
          this.tableData = data.result.list
          this.page.total = data.result.count
          for (let i = 0; i < data.result.list.length; i++) {
            if (!data.result.list[i].flowState) {
              let flowState = {}
              this.$set(data.result.list[i], 'flowState', flowState)
            }
          }
          this.tableData.forEach(row => {
            if (!(row.operateOld === undefined)) {
              row.operateOld = JSON.parse(row.operateOld)
            }
            if (!(row.operateNew === undefined)) {
              row.operateNew = JSON.parse(row.operateNew)
            }
          })
        }
        this.loading = false
      })
    },
    handleSizeChange () {},
    // 当前页改变
    handleCurrentChange (e) {
      this.page.pageNo = e
      this.getList(this.page)
    },
    close (type) {
      if (type === 'edit') {
        this.editVisible = false
        return
      }
      this.viewVisible = false
    },
    tableRowClassName ({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      } else {
        return 'success-row'
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.title {
  height: 16px;
  font-size: 16px;
  font-weight: 400;
  color: #333333;
}
.details {
  width: 824px;
  margin: 0 auto;
  .details-item {
    display: flex;
    div {
      border: 1px solid#DDDDDD;
      width: 33%;
      margin: 0px 0px -1px -1px;
    }
    .item1 {
      display: flex;
      padding-right: 10px;
      .itemKey1 {
        border-right: 1px solid #dddddd;
      }
    }
  }
}
::v-deep .tableDialog.el-dialog__wrapper .el-dialog{
  .el-dialog__body{
    padding-bottom: 4px !important;
  }
  .el-dialog__footer {
    padding: 10px 0 !important;
  }
}

</style>
